<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yuxin.common.util.*" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.google.gson.Gson" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    Connection conn = DBUtil.getConnection();
	Map user = ((Map)session.getAttribute("user"));
    try{
    	List dataList = DBUtil.queryList(conn,"SELECT ID,TITLE,TITLE_IMG,PRICE,AMOUNT,UPDATE_TIME FROM P_GOODS WHERE TRADE_ID = ? AND STATUS = '2' ORDER BY CREATE_TIME DESC ",user.get("SRC_ID"));
        request.setAttribute("dataList",dataList);
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        DBUtil.close(conn);
    }
%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/meta.jsp" %>
    <title>${site_title}</title>
</head>
<body>
<div class="zx-container" >
	<%@ include file="/trader/menu.jsp" %>
	<div class="span9 offset3">
		<%@ include file="/header_bg.jsp" %>
        <div class="row-fluid zx-bg-cont">
            <div class="span12 subpage-title">
                <div class="left"><h4 id="headertext" class="title">仓库中的商品</h4></div>
                <div class="right">
<!--                    <button class="btn btn-success" onclick="do_add()"><i class="icon icon-plus icon-white"></i> 新增</button>-->
                </div>
            </div>
            <table class="table table-bordered" style="border: 1px solid #CCC;">
                <thead>
                    <tr>
                        <th>商品</th>
                        <th>价格</th>
                        <th>数量</th>
                        <th>上架时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
            	<c:forEach items="${dataList}" var="data" varStatus="status">
            		<tr id="${data.ID}">
            			<td class="table-img-td">
		                	<c:if test="${data.TITLE_IMG !=null && data.TITLE_IMG !=''}">
	            				<img class="table-img" src="${ctx}/${data.TITLE_IMG}" />
            				</c:if>
            				<div class="table-img-div">${data.TITLE}</div>
            			</td>
            			<td>￥${data.PRICE}</td>
            			<td>${data.AMOUNT}</td>
            			<td><fmt:formatDate value="${data.UPDATE_TIME}" pattern="yyyy-MM-dd"/></td>
            			<td class="align-center">
            				<div class="btn-group">
            					<a href="${ctx}/trader/publish.jsp?status=2&id=${data.ID}" class="btn btn-mini"><i class="icon-edit"></i>编辑</a>
            					<a href="#" onclick="saleOff(this,'${data.ID}')" class="btn btn-mini"><i class="icon-arrow-down"></i>下架</a>
            				</div>
            			</td>
            		</tr>
            	</c:forEach>
            </table>
        </div>
		<%@ include file="/footer_bg.jsp" %>
	</div>
</div>
<script>
$(document).ready(function(){
	$("#menu_sell").addClass("active");
});
//商品下架
function saleOff(ele,id){
    $(ele).addClass("disabled");
    $.post("${ctx}/trader/trader.action.jsp",{action:"saleOnOff","ID":id,"STATUS":"1"},function(data){
    	$(ele).removeClass("disabled");
        if(data.isSuccess){
            $.pnotify({
                title: '消息提示',
                text: '操作成功!',
                type: 'success',
                animation: 'fade',
                shadow: false,
                delay: 1000
            });
            $("#"+id).remove();
        }else{
            $.pnotify({
                title: '消息提示',
                text: '操作失败：'+data.error,
                type: 'error',
                animation: 'fade',
                hide:false,
                shadow: false
            });
        }
    });
}
</script>
</body>
</html>